package net.qhzw.vip.qiyu.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * 系统菜单
 */
@TableName(value = "sys_menu")
public class SysMenu {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.INPUT)
    private Long id;

    /**
     * 上级菜单ID
     */
    @TableField(value = "parent_id")
    private Long parentId;

    /**
     * 上级菜单唯一KEY值
     */
    @TableField(value = "parent_key")
    private String parentKey;

    /**
     * 类型 1-分类 2-节点
     */
    @TableField(value = "`type`")
    private Byte type;

    /**
     * 名称
     */
    @TableField(value = "`name`")
    private String name;


    /**
     * 权限标识
     */
    @TableField(value = "`permission`")
    private String permission;

    /**
     * 描述
     */
    @TableField(value = "`desc`")
    private String desc;

    /**
     * 目标地址
     */
    @TableField(value = "target_url")
    private String targetUrl;

    /**
     * 排序索引
     */
    @TableField(value = "`sort`")
    private Integer sort;

    /**
     * 状态 0-无效； 1-有效；
     */
    @TableField(value = "`status`")
    private Byte status;

    /**
     * 创建人
     */
    @TableField(value = "create_by")
    private Long createBy;

    /**
     * 修改人
     */
    @TableField(value = "modify_by")
    private Long modifyBy;

    /**
     * 创建时间
     */
    @TableField(value = "`created`")
    private Date created;

    /**
     * 修改时间
     */
    @TableField(value = "last_update_time")
    private Date lastUpdateTime;


    @TableField(exist = false)
    @ApiModelProperty("该菜单的子菜单")
    private List<SysMenu> childs;

    public SysMenu() {
    }

    public SysMenu(Long id, Long parentId, String parentKey, Byte type, String name, String permission, String desc, String targetUrl, Integer sort, Byte status, Long createBy, Long modifyBy, Date created, Date lastUpdateTime, List<SysMenu> childs) {
        this.id = id;
        this.parentId = parentId;
        this.parentKey = parentKey;
        this.type = type;
        this.name = name;
        this.permission = permission;
        this.desc = desc;
        this.targetUrl = targetUrl;
        this.sort = sort;
        this.status = status;
        this.createBy = createBy;
        this.modifyBy = modifyBy;
        this.created = created;
        this.lastUpdateTime = lastUpdateTime;
        this.childs = childs;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getParentKey() {
        return parentKey;
    }

    public void setParentKey(String parentKey) {
        this.parentKey = parentKey;
    }

    public Byte getType() {
        return type;
    }

    public void setType(Byte type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getTargetUrl() {
        return targetUrl;
    }

    public void setTargetUrl(String targetUrl) {
        this.targetUrl = targetUrl;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Long getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(Long modifyBy) {
        this.modifyBy = modifyBy;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public List<SysMenu> getChilds() {
        return childs;
    }

    public void setChilds(List<SysMenu> childs) {
        this.childs = childs;
    }

    /**
     * 获取菜单的唯一Key凭证
     *
     * @return
     */
    public String menuKey() {
        if (!StringUtils.isEmpty(parentKey)) {
            return parentKey + "." + id;
        } else {
            return id.toString();
        }
    }
}